<?php

defined( 'IN_CLASS' ) or die( 'Access Error!' );

class control {
	
	protected $chash = 'jdkslai3892feklajfexxfekae892839fdskla478700f8u8f9das';
	
	public function _chechlogin() { //检查登陆cookie
		$return = -3;
		$sC = func::input( 'classauth', 's', 'COOKIE' );
		$ip = func::getclientip();
		if ( strlen( $sC ) > 40 ) {
			list( $aC['id'], $aC['power'], $aC['time'], $aC['ip'], $sign ) = explode( ',', $sC );
			$sC = "{$aC['id']},{$aC['power']},{$aC['time']},{$ip}";
			if ( $sign == sha1( $sC . $this->chash ) && $aC['ip'] == $ip ) {
				model::online()->fresh( $aC['id'] ); //刷新个人在线记录
				model::online()->deloffline(); //删除不在线的用户
				return $aC;
			}
			
			$return = -2; //验证失败
			if ( $aC['ip'] != $ip ) {
				$return = -1; //ip已切换，不承认此cookie
			}
		}
		
		func::redirect( 'index.php?m=login&a=index&error='.$return );
	}
	
	public function _genuser() { //根据外部输入构造编辑或者添加用户需要的数组
		$detail = array();
		isset( $_REQUEST['name'] ) && $detail['name'] = func::input( 'name' );
		isset( $_REQUEST['sex'] ) && $detail['sex'] = func::input( 'sex', 'i' );
		isset( $_REQUEST['mobile'] ) && $detail['mobile'] = func::input( 'mobile' );
		isset( $_REQUEST['qq'] ) && $detail['qq'] = func::input( 'qq', 'i' );
		isset( $_REQUEST['birthday'] ) && $detail['birthday'] = func::input( 'birthday' );

		isset( $_REQUEST['unit'] ) && $detail['unit'] = func::input( 'unit' );
		isset( $_REQUEST['address'] ) && $detail['address'] = func::input( 'address' );
		isset( $_REQUEST['phone'] ) && $detail['phone'] = func::input( 'phone' );
		isset( $_REQUEST['postcode'] ) && $detail['postcode'] = func::input( 'postcode', 'i' );
		isset( $_REQUEST['email'] ) && $detail['email'] = func::input( 'email' );
		isset( $_REQUEST['msn'] ) && $detail['msn'] = func::input( 'msn' );
		isset( $_REQUEST['brief'] ) && $detail['brief'] = func::input( 'brief' );
		/*
		isset( $_REQUEST['sign1'] ) && $detail['sign1'] = func::input( 'sign1' );
		isset( $_REQUEST['sign2'] ) && $detail['sign2'] = func::input( 'sign2' );
		isset( $_REQUEST['sign3'] ) && $detail['sign3'] = func::input( 'sign3' );
		isset( $_REQUEST['currsign'] ) && $detail['currsign'] = func::input( 'currsign', 'i' );
		*/
		return $detail;
	}
}